package os;


/**
 *
 * @author Paulius Dambrauskas
 */
class MainProc extends Process {
    int govId = 0;
    ResourceElement e;
    @Override
    public void runProcess() {
        this.changeStepCell(step);
        switch(step){
            case 1:{
                //changeStepCell(1);
                OS.askRes("Užduoties duomenys", selfId);
                incStep(1);
                break;
            }
            case 2:{
                //changeStepCell(2);
                e = this.takeFromGivenResources("Užduoties duomenys");
                String task = (String) e.value.toString();
                if(task.startsWith("DESTROY:")){
                    String[] destroy = task.split(":");
                    govId = Integer.parseInt(destroy[1]);   
                }
                
                if(govId == 0)
                    incStep(1);
                else
                    incStep(2);
                break;
            }
            case 3:{
                //changeStepCell(3);
                OS.createProc(selfId, 2, 50, JobGovernor.class);
                 
                OS.processes.get(OS.processCount - 1).givenResources.add(e);
                setStep(1);
                break;
            }
            case 4:{
                //changeStepCell(4);
                OS.destroyProc(govId);
                setStep(1);
                break;
            }
        }
    }
 
}
